"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.serve = void 0;
const log4js_1 = require("log4js");
const node_schedule_1 = require("node-schedule");
const reptile_1 = require("./reptile");
const route_1 = require("./route");
const utils_1 = require("./utils");
const qiniuLoad_1 = require("./utils/qiniuLoad");
const console_1 = require("console");
function serve(config) {
    return __awaiter(this, void 0, void 0, function* () {
        if (config.logger)
            (0, log4js_1.configure)(config.logger);
        const { dbName, dbUrl, access, secret, bucket, hero, hero_alis } = config;
        const dbConeect = new utils_1.connecDB(dbUrl, dbName);
        const qiniuLoad = new qiniuLoad_1.qiniu(access, secret, bucket);
        const colOPGG = yield dbConeect.mongoCol('opgg');
        yield (0, reptile_1.opggIndex)(hero, colOPGG, qiniuLoad, hero_alis);
        (0, node_schedule_1.scheduleJob)('* */10 * * *', () => __awaiter(this, void 0, void 0, function* () {
            console.error((0, console_1.time)());
            yield (0, reptile_1.opggIndex)(hero, colOPGG, qiniuLoad, hero_alis);
        }));
        yield (0, route_1.createRoute)(8088, colOPGG);
    });
}
exports.serve = serve;
